import dayjs from 'dayjs'
import 'dayjs/locale/zh-cn'

dayjs.locale('zh-cn')

const advancedFormat = require('dayjs/plugin/advancedFormat')
dayjs.extend(advancedFormat)

/**
 * dayjs
 * @param{string} date
 * @param{string} option
 * @returns {function}
 */
export function $dayjs(date, option = '') {
  return dayjs(date, option)
}

/**
 * 本地存储操作
 */
class Storage {
  /**
   * 插入指定key值数据
   * @param{string} key
   * @param{any} date
   */
  setStorageSync(key, date) {
    if (typeof key === 'string' || typeof key === 'number') {
      return uni.setStorageSync(key, date)
    }
  }

  // 获取指定key值本地数据
  getStorageSync(key) {
    return uni.setStorageSync(key)
  }

  // 删除单条 本地存储
  removeStorageSync(key) {
    return uni.removeStorageSync(key)
  }

  // 清除所有本地存储
  clear() {
    return uni.clearStorageSync()
  }
}
export const storage = new Storage()
